home *** CD-ROM | disk | FTP | other *** search
- unit SetEditorFormU;
-
- {$ifdef Ver100} { Delphi 3.0x }
- {$define DelphiLessThan4}
- {$define DelphiLessThan5}
- {$endif}
- {$ifdef Ver110} { C++ Builder 3.0x }
- {$define DelphiLessThan4}
- {$define DelphiLessThan5}
- {$endif}
- {$ifdef Ver120} { Delphi 4.0x }
- {$define DelphiLessThan5}
- {$endif}
-
- interface
-
- uses
- TypInfo,
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- CheckLst, StdCtrls;
-
- type
- TSetEditorForm = class(TForm)
- lstEnums: TCheckListBox;
- btnOK: TButton;
- btnCancel: TButton;
- procedure btnOKClick(Sender: TObject);
- private
- FPropInfo: PPropInfo;
- FObject: TObject;
- SetTypeInfo, EnumTypeInfo: PTypeInfo;
- SetTypeData, EnumTypeData: PTypeData;
- public
- constructor Create(Obj: TObject; PropInfo: PPropInfo);
- {$ifndef DelphiLessThan4}reintroduce;{$endif}
- end;
-
- var
- SetEditorForm: TSetEditorForm;
-
- implementation
-
- {$R *.DFM}
-
- uses
- PropertyHelper;
-
- { TSetEditorForm }
-
- constructor TSetEditorForm.Create(Obj: TObject; PropInfo: PPropInfo);
- var
- S: ^ShortString;
- Loop: Integer;
- IntSet: TIntegerSet;
- begin
- inherited Create(Application);
- FObject := Obj;
- FPropInfo := PropInfo;
- IntSet := TIntegerSet(GetOrdProp(FObject, FPropInfo));
- SetTypeInfo := FPropInfo.PropType^;
- SetTypeData := GetTypeData(SetTypeInfo);
- EnumTypeInfo := SetTypeData^.CompType^;
- EnumTypeData := GetTypeData(EnumTypeInfo);
- with EnumTypeData^ do
- begin
- S := @NameList;
- //Loop through the enum values that can be in
- //the set and add them to a check list box
- for Loop := MinValue to MaxValue do
- begin
- lstEnums.Items.Add(S^);
- if GetEnumValue(EnumTypeInfo, lstEnums.Items[lstEnums.Items.Count - 1]) in IntSet then
- lstEnums.State[lstEnums.Items.Count - 1] := cbChecked;
- Inc(Integer(S), Length(S^) + 1);
- end
- end
- end;
-
- procedure TSetEditorForm.btnOKClick(Sender: TObject);
- var
- Loop: Integer;
- IntSet: TIntegerSet;
- begin
- IntSet := [];
- for Loop := 0 to lstEnums.Items.Count - 1 do
- if lstEnums.State[Loop] = cbChecked then
- Include(IntSet, GetEnumValue(EnumTypeInfo, lstEnums.Items[Loop]));
- SetOrdProp(FObject, FPropInfo, Integer(IntSet))
- end;
-
- end.
-